﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace WeiTap.RestClient
{
    /// <summary>
    /// 封装Rest Api返回结果
    /// </summary>
    public interface IRestResponse
    {
        /// <summary>
        /// 对应请求数据包
        /// </summary>
        IRestRequest Request { get; set; }
        /// <summary>
        /// 返回的链接地址，如果页面发生跳转则不同于请求地址
        /// </summary>
        Uri ReponseUri { get; set; }

        /// <summary>
        /// MIME类型
        /// </summary>
        string ContentType { get; set; }
        /// <summary>
        /// 长度
        /// </summary>
        int ConentLength { get; set; }
        /// <summary>
        /// 编码格式
        /// </summary>
        string ContentEncoding { get; set; }
        /// <summary>
        /// 返回数据的字符串表现形式
        /// </summary>
        string Content { get; set; }
        /// <summary>
        /// 返回数据的字节码表现形式
        /// </summary>
        byte[] RawBytes { get; set; }
        /// <summary>
        /// HTTP状态码
        /// </summary>
        HttpStatusCode StatusCode { get; set; }
        /// <summary>
        /// 请求状态码
        /// </summary>
        ResponseStatus ResponseStatus { get; set; }

        /// <summary>
        /// 请求是否成功，取决于http状态码和Response返回状态码
        /// </summary>
        bool IsSuccessful { get; set; }
        /// <summary>
        /// 发送响应的服务器的名称
        /// </summary>
        string Server { get; set; }
        /// <summary>
        /// Cookies
        /// </summary>
        IList<RestResponseCookie> Cookies { get; set; }
        /// <summary>
        /// 返回的头部信息
        /// </summary>
        IList<Parameter> Headers { get; set; }
        /// <summary>
        /// 非HTTP请求发送错误以外的其他错误信息
        /// </summary>
        string ErrorMessage { get; set; }
        /// <summary>
        /// 请求期间抛的错误
        /// </summary>
        /// <summary>Http协议错误不会在这里出现</summary>
        Exception ErrorException { get; set; }
        /// <summary>
        /// HTTP协议版本号
        /// </summary>
        Version ProtocolVersion { get; set; }
    }

    /// <summary>
    /// 返回指定类型的数据
    /// </summary>
    /// <typeparam name="T">数据类型</typeparam>
    public interface IRestResponse<T> : IRestResponse
    {
        /// <summary>
        /// 指定类型的数据
        /// </summary>
        T Data { get; set; }
    }
}
